﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_gold_manageGold : System.Web.UI.Page
{
    db_gold gold = new db_gold();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx");  // 此处用户权限验证
        if (!IsPostBack)
        {

            string sell = Request.QueryString["sell"];
            string use = Request.QueryString["use"];
            string goldNum = Request.QueryString["goldNum"];
            if (null != sell && sell.Length > 0)
            {
                if (sell.Equals("all"))
                    rbtn_all.Checked = true;
                if (sell.Equals("1"))
                    rbtn_yes.Checked = true;
                if (sell.Equals("0"))
                    rbtn_no.Checked = true;
            }

            if (null != use && use.Length > 0)
            {
                if (use.Equals("all"))
                    rbtn_u_all.Checked = true;
                if (use.Equals("1"))
                    rbtn_u_y.Checked = true;
                if (use.Equals("0"))
                    rbtn_u_n.Checked = true;
            }

            if (null != goldNum && goldNum.Length > 0) {
                ddl_gold.SelectedValue = goldNum;
            }

            btn_search_Click(sender, e);
        }
    }
    protected void btn_search_Click(object sender, EventArgs e)
    {
        string sell = "";
        string use = "";
        string goldNum = "";
        goldNum = ddl_gold.SelectedValue;

        if (rbtn_all.Checked)
        {
            sell = "all";
        }
        else if (rbtn_yes.Checked)
        {
            sell = "1";
        }
        else
        {
            sell = "0";
        }
        if (rbtn_u_all.Checked)
        {
            use = "all";
        }
        else if (rbtn_u_y.Checked)
        {
            use = "1";
        }
        else
        {
            use = "0";
        }
        DataSet ds = gold.selectGold_search(sell, use, goldNum);
        //分页 开始 -------
        firstPage.NavigateUrl = null;
        prePage.NavigateUrl = null;
        nextPage.NavigateUrl = null;
        endPage.NavigateUrl = null;


        int CurPage;
        if (sender.GetType().Equals(new Button().GetType()))
        {
            CurPage = 1;
        }
        else
        {
            if (Request.QueryString["Page"] != null && Convert.ToInt32(Request.QueryString["Page"]) > 0)
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            else
                CurPage = 1;
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables[0].DefaultView;
        ps.AllowPaging = true;
        //每个页面显示的条数
        ps.PageSize = 15;
        onePage.Text = ps.PageSize.ToString();
        //求数据的总数
        allMsg.Text = ps.DataSourceCount.ToString();
        ps.CurrentPageIndex = CurPage - 1;
        //求总页
        allPages.Text = ps.PageCount.ToString();
        nowPage.Text = CurPage.ToString();
        //将数据源与控件绑定
        goldList.DataSource = ps;
        goldList.DataBind();

        //上一页
        if (!ps.IsFirstPage)
        {
            firstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1&sell=" + sell + "&use=" + use + "&goldNum=" + goldNum;
            prePage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&sell=" + sell + "&use=" + use + "&goldNum=" + goldNum;
        }
        //下一页
        if (!ps.IsLastPage)
        {
            nextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&sell=" + sell + "&use=" + use + "&goldNum=" + goldNum;
            endPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(ps.PageCount) + "&sell=" + sell + "&use=" + use + "&goldNum=" + goldNum;
        }
        //分页 结束 -------
    }
}